home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / macros / Text / Insert_Date.bsh < prev    next >
Encoding:
Text File  |  2004-08-29  |  2.5 KB  |  81 lines

  1. /*
  2.  * Insert_Date.bsh - a BeanShell macro script for the
  3.  * jEdit text editor - insert current date and "Internet Time"
  4.  * at current caret position
  5.  * Copyright (C) 2001 John Gellene (on behalf of author)
  6.  * jgellene@nyc.rr.com
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License
  10.  * as published by the Free Software Foundation; either version 2
  11.  * of the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with the jEdit program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  *
  22.  * $Id: Insert_Date.bsh,v 1.3 2004/03/08 04:29:12 spestov Exp $
  23.  */
  24.  
  25. // Inserts the current date and Internet Time at the caret position
  26. // "Internet Time" is a new and easy way to measure time across the world
  27. // To find more "Internet Time"-related information go to
  28. // http://www.swatch.com/alu_beat/fs_itime.html
  29.  
  30. // Wed Jan 31 03:12:33 AKST 2001 @550 /Internet Time/
  31.  
  32. void insertDate()
  33. {
  34.     Calendar rightNow = Calendar.getInstance();
  35.  
  36.     // zone offset with daylight savings
  37.     int zoffset = (rightNow.get(Calendar.ZONE_OFFSET) +
  38.     rightNow.get(Calendar.DST_OFFSET)) / 60000;
  39.  
  40.     // parsing current hour, minute and second
  41.     double h = rightNow.get(Calendar.HOUR_OF_DAY);
  42.     double m = rightNow.get(Calendar.MINUTE);
  43.     double s = rightNow.get(Calendar.SECOND);
  44.  
  45.     // calculating internet time
  46.     double swatch = Math.floor
  47.     ((h * 3600 + ((m - zoffset + 60) * 60) + s) * 1000 / 86400);
  48.     if (swatch >= 1000)
  49.         swatch -= 1000;
  50.     else if (swatch < 0)
  51.         swatch += 1000;
  52.  
  53.     // inserting date and internet time to textarea
  54.     textArea.setSelectedText(Calendar.getInstance().getTime().toString()
  55.         + " @" + (int)swatch + " /Internet Time/");
  56. }
  57.  
  58. if(buffer.isReadOnly())
  59.     Macros.error(view, "Buffer is read-only.");
  60. else
  61.     insertDate();
  62.  
  63. /*
  64.     Macro index data (in DocBook format)
  65.  
  66. <listitem>
  67.     <para><filename>Insert_Date.bsh</filename></para>
  68.     <abstract><para>
  69.         Inserts the current date and time in the current buffer.
  70.     </para></abstract>
  71.     <para>
  72.         The inserted text includes a representation of the time in the
  73.         <quote>Internet Time</quote> format.
  74.     </para>
  75. </listitem>
  76.  
  77. */
  78.  
  79. // end Insert_Date.bsh
  80.  
  81.